<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link href="../bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet" />
		<script src="../js/jquery-3.5.1.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			html,
			body,
			.container {
				height: 100%;
				width: 100%;
				margin: 0;
				padding: 0;
			}

			.top {
				width: 100%;
				height: 80px;
				background: url(../img/Snipaste_2020-08-25_16-41-00.png);
			}

			.right {
				position: relative;
				width: 80%;
				height: 80%;
				top: -110px;
				left: 265px;
			}
			form{
				position: relative;
				left: 420px;
			}
		</style>
	</head>
	<body>
		<div class="container">
			<div class="top">
				<span style="font-size: 30px;position: relative;top:20px;left: 40px;">宿舍管理系统</span>
				<span style="font-size: 15px; position: relative; top:35px; left: 1000px;">当前用户:</span>
			</div>

			<div class="list-group" style="width: 15%; position: relative;top:55px;left: 20px;">
				<a href="index01.html" class="list-group-item active">
					首页
				</a>
				<a href="qq02.html" class="list-group-item">缺勤记录</a>
				<a href="xg.html" class="list-group-item">修改密码</a>
				<a href="../login.html" class="list-group-item">退出系统</a>
			</div>
			<div class="right" >
				<h4><strong>宿舍管理员管理</strong></h4>
			<form id="form">
				原密码：&nbsp;&nbsp;&nbsp;<input type="password" name="password" /></br>
				新密码：&nbsp;&nbsp; <input type="password" name="password1"/></br>
				确认密码：<input type="password" name="password2" /></br>
				<button type="button" onclick="save()" class="btn btn-primary" style="margin-left: 65px;margin-top: 10px;" >保存</button>
			</form>
			<script type="text/javascript">
				let data = JSON.parse(localStorage.getItem("users"));
				let account = sessionStorage.getItem("account");
				function save(){
				    let password = $("input[name='password']").val();
					let password1 = $("input[name='password1']").val();
					let password2 = $("input[name='password2']").val();
					for(let index in data){
						let item = data[index];
							if (!password){
								alert("请输入原密码!");
								return;
							}
							if (password===item.password && account === item.account && password1 ===password2){
									item.password = password1;
									localStorage.setItem("users",JSON.stringify(data));
									alert("修改成功");
							}
							else{
								alert("两次密码不一致！");
							}
					}
				}
			</script>
			</div>
	
				
		</div>
	</body>
</html>
